function initThree() {
    let stats = initStats();
    let controlls = new function(){
        this.cubeRotateSpeed = 0.02;
        this.ballGravity = 9.8;
    };
    let scene = new THREE.Scene();
    let camera = new THREE.PerspectiveCamera(45, window.innerWidth/window.innerHeight, 0.1, 1000);
    let renderer = new THREE.WebGLRenderer();
    renderer.setClearColor(new THREE.Color(200,200,200));
    renderer.setSize(window.innerWidth, window.innerHeight);
    renderer.shadowMap.enabled = true; //启用阴影
    // 创建一个平面并添加到场景
    let planeGeometry = new THREE.PlaneGeometry(60, 60);
    let planeMaterial = new THREE.MeshLambertMaterial({color: 0xcccccc});
    let plane = new THREE.Mesh(planeGeometry,planeMaterial);
    plane.position.x = 15;
    plane.position.y = 0;
    plane.position.z = 0;
    plane.rotation.x = -0.5 * Math.PI;
    scene.add(plane);
    // 创建一个方块并添加到场景
    let cubeGeometry = new THREE.CubeGeometry(4, 4, 4);
    let cubeMaterial = new THREE.MeshLambertMaterial({color: 0xff0000});
    let cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
    cube.position.x = -4;
    cube.position.y = 3;
    cube.position.z = 0;
    scene.add(cube);
    // 创建一个球体并添加到场景
    let ballGeometry = new THREE.SphereGeometry(4, 20, 20);
    let ballMaterial = new THREE.MeshLambertMaterial({color: 0x7777ff});
    let ball = new THREE.Mesh(ballGeometry, ballMaterial);
    ball.position.x = 20;
    ball.position.y = 30;
    ball.position.z = 2;
    scene.add(ball);
    camera.position.x = -30;
    camera.position.y = 40;
    camera.position.z = 30;
    camera.lookAt(scene.position);
    // 添加一个光源
    let light = new THREE.SpotLight(0xffffff);
    light.position.set(-40, 60, -10);
    scene.add(light);
    plane.receiveShadow = true;
    cube.castShadow = true;
    ball.castShadow =true;
    light.castShadow = true;
    document.body.appendChild(renderer.domElement);
    let gui = new dat.GUI();
    gui.add(controlls, 'cubeRotateSpeed', 0, 0.5);
    gui.add(controlls, 'ballGravity', 0, 100);
    let t = 0;
    let v = 0;
    render();
    function render() {
        stats.update();
        cube.rotation.x += controlls.cubeRotateSpeed;
        cube.rotation.y += controlls.cubeRotateSpeed;
        cube.rotation.z += controlls.cubeRotateSpeed;
        v += controlls.ballGravity * (1/20);
        ball.position.y -= v * (1/20);
        if(ball.position.y <= 4){
            v = -v * 0.9;
        }
        t += 1/60;
        requestAnimationFrame(render);
        renderer.render(scene, camera);
    }
    function initStats() {
        let stats = new Stats();
        stats.setMode(0); // 0: fps, 1: ms
        // Align top-left
        stats.domElement.style.position = 'absolute';
        stats.domElement.style.left = '0px';
        stats.domElement.style.top = '0px';
        document.body.appendChild(stats.domElement);
        return stats;
    }
}
window.onload = initThree;